<?php
class tests_PagesGroup extends PagesGroup {
	function getLayoutName() {
		if ( Request::getPage() == 'afc' ) {
			return "layout2";
		}
		return parent::getLayoutName();
	}
	
	function beforePage() {
		echo "<br>before<br>";
	}
	
	function afterPage() {
		echo "<br>after<br>";
	}
	
	function default_page() {
		echo "qwqww";
	}
	
	function pform1_page() {
		Sys::importLib("PersistentForm", true);
		$form = new PersistentForm("LoginForm", 'tests.php', 'onSuccess', 'onSuccessClient');
		
		$form->beginForm(); 
		//$form->render($data)
		?>
		<table>
		<tr>
			<td>Email</td>
			<td>
				<?php
				$form->addTextInput("email", "gabriel.dodan@gmail.com")
					->setValidators( 
							array(
								new PF_Validator(PF_Validator::REGEXP, "/.*dodan.*/", "Must contain 'dodan'"),
								new PF_Validator(PF_Validator::FUNC, "validator_checkEmail")	 
							)
					)
					->setAttr("style", "border-color:red;")
					->setAttr("class", "classbeton")
					->setAfterControlHtml("qwweq")
					->render();
				?>
			</td>
		</tr>
		<tr>
			<td>Email</td>
			<td>
				<?php
				$form->addButtonSubmit("qwq", "Send")->render();
				?>
			</td>
		</tr>
		</table>		
		<?php
		$form->endForm();
		$form->render();
		
		$form = new PersistentForm("LoginForm2", 'tests.php', 'onSuccess', 'onSuccessClient');
		
		$form->beginForm(); 
		?>
		<table>
		<tr>
			<td>Email 2</td>
			<td>
				<?php
				$form->addTextInput("email", "gabriel.dodan@gmail.com")
					->setValidators( 
							array(
								new PF_Validator(PF_Validator::REGEXP, "/.*dodan.*/", "Must contain 'dodan'"),
								new PF_Validator(PF_Validator::FUNC, "validator_checkEmail")	 
							)
					)
					->setAttr("style", "border-color:red;")
					->setAttr("class", "classbeton")
					->setAfterControlHtml("qwweq")
					->render();
				?>
			</td>
		</tr>
		<tr>
			<td>Email</td>
			<td>
				<?php
				$form->addButtonSubmit("qwq", "Send 2")->render();
				?>
			</td>
		</tr>
		</table>		
		<?php
		$form->endForm();
		$form->render();
		
	}
	
	function pform_new_page() {
		
		require_once Locator::pathAppDir() . "/forms/test.php";
		$model = new LoginForm();
		
		$form = new PersistentForm("LoginForm", $model);
		$form->render();
	}
	
	function pform_page() {
		
		Sys::importLib("PersistentForm", true);
		$form = new PersistentForm("LoginForm", 'tests.php', 'onSuccess', 'onSuccessClient');
		
		$form->beginForm(); 
		?>
		<script>
		function onSuccessClient() {
			console.log("BEST");
		}
		</script>
		<table>
		<tr>
			<td>Email</td>
			<td>
				<?php
				$form->addTextInput("email", "gabriel.dodan@gmail.com")
					->setValidators( 
							array(
								new PF_Validator(PF_Validator::REGEXP, "/.*dodan.*/", "Must contain 'dodan'"),
								new PF_Validator(PF_Validator::FUNC, "validator_checkEmail")	 
							)
					)
					->setAttr("style", "border-color:red;")
					->setAttr("class", "classbeton")
					->setAfterControlHtml("qwweq")
					->render();
				?>
				<input type="button" value="checkemail" onclick="checkEmail()" />
				<script>
					function checkEmail() {
						pd.pform.get('<?= $form->getName() ?>').callFunc('validateEmail', "email=" + $("#email").val());
					}
				</script>
			</td>
		</tr>
		<tr>
			<td>Detalii</td>
			<td>
				<?php
				$form->addTextArea("detalii", "qweqwe qweqwe qwewq qweq ")
					->setAttr("cols", "50")
					->setAttr("rows", "10")
					->render();	
				?>
			</td>
		</tr>
		
		<tr>
			<td>Locale</td>
			<td>
				<?php
				$form->addSelect("locale", array('en' => 'en', 'fr' => 'fr', 'ro' => 'ro'))
					->setAttr("onchange", "localeChange()")
					->render();	
				?>
				<script>
					function localeChange() {
						$( "#LoginForm__start-date" ).datepicker( "option", $.datepicker.regional[ $("#LoginForm__locale").val() ] );
					}
				</script>
			</td>
		</tr>
		
		<tr>
			<td>Date</td>
			<td>
				<?php
				$form->addDatepicker("start-date", '07.02.2011', 'dd.mm.yy')
					->setOption("appendText", "'qweqw'")
					->render();
				?>
			</td>
		</tr>
		
		<tr>
			<td>Date fr</td>
			<td>
				<?php
				$form->addDatepicker("start-date-fr", '07.02.2011', '', 'fr')
					->setOption("autoSize", "true")
					->setOption("appendText", "'FR'")
					->render();
				?>
			</td>
		</tr>
		
		<tr>
			<td>Date ro</td>
			<td>
				<?php
				$form->addDatepicker("start-date-ro", '07.02.2011', '', 'ro')
					->setOption("autoSize", "true")
					->setOption("appendText", "'RO'")
					->render();
				?>
			</td>
		</tr>
		
		<tr>
			<td>Fname</td>
			<td>
				<?php
				$form->addTextInput("fname", "First Name")
					->setAfterControlHtml("<div style=\"font-size:10px;\">tip</div>")
					->setBeforeControlHtml("before")
					->render();
				?>
			</td>
		</tr>
		<tr>
			<td>Country</td>
			<td>
				<?php 
				$form->addSelect("country", array('ro'=>'Romania', 'en' => 'England', 'fr' => 'France'))
					->setIsMultiple(TRUE)
					->setValue(array('en', 'fr'))
					->render();	
				?>
			</td>
		</tr>
		<tr>
			<td>Cities</td>
			<td>
				<?php
				function customRenderer(PFC_Select $control) {
					$items = $control->getItems(); 
					$item  = NULL; /* @var $item PFCI_Option */
					foreach ($items AS $item) {
						if ( $item->getIsSelected() ) {
							$item->setAttr("style", "color:red;");
						}
						$item->render();
					}
				}	 
				  
				$form->addSelect("city", array('is'=>'Iasi', 'b' => 'Buchares', 'bt' => 'Botosani'), FALSE)
					->setValue(array('b'))
					->setItemsRenderer("customRenderer")
					->setValidators( array(new PF_Validator(PF_Validator::REGEXP, "/is/", "Iasi is a must")) )
					->render();
				?>
			</td>
		</tr>
		<tr>
			<td>Readead rules ?</td>
			<td>
				<?php 
				$form->addCheckbox("rules-read", false)->render(); 
				?>
			</td>
		</tr>
		<tr>
			<td>Readead rules 2 ?</td>
			<td>
				<?php 
				$form->addRadio("rules2-read", true)->render(); 
				?>
			</td>
		</tr>
		<tr>
			<td>Categories</td>
			<td>
				<?php
				$form->addCheckboxList("categories", array('1' => "Cat 1", '2' => 'Cat 2', '3' => 'Cat 3'), array('1', '2'))
					->setItemsLabelPosition('left')
					->setItemsLayout('vertical')
					->render();	 
				?>
			</td>
		</tr>
		
		<tr>
			<td>Sub categories</td>
			<td>
				<?php
				$form->addRadioList("subcategories", array('1' => "Cat 1", '2' => 'Cat 2', '3' => 'Cat 3'), array('2') )
					->setItemsLabelPosition('right')
					->setItemsLayout('vertical')
					->render();	 
				?>
			</td>
		</tr>
		
		<tr>
			<td>Sub sub categories</td>
			<td>
				<?php
				$form->addRadioList("subsubcategories", array('1' => "Cat 1", '2' => 'Cat 2', '3' => 'Cat 3'), array('3') )
					->setItemsLabelPosition('right')
					->setItemsLayout('vertical')
					->render();
				?>
			</td>
		</tr>
		
		<tr>
			<td>Ajax file upload 1</td>
			<td>
				<?php
				$afu = $form->addAjaxFileUpload("ajaxfileupload1", "werwe"); 
				$afu->setAttr("style", "margin:10px; padding:2px; border:2px solid red;")
				->render(); 
				?>
			</td>
		</tr>
		<tr>
			<td>Avatar 2</td>
			<td>
				<?php 
				$form->addFileUpload("avatar2")
					->setAttr("onchange", "alert($('#LoginForm__avatar2').val())")
					->render(); 
				?>
			</td>
		</tr>
		<tr>
			<td>Ajax file upload 2</td>
			<td>
				<?php
				$afu = $form->addAjaxFileUpload("ajaxfileupload2", "werwe"); 
				$afu->render(); 
				?>
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td>
				<?php $form->addButtonSubmit("submitfrm", "Send")->render(); ?>
			</td>
		</tr>
		</table>
		
		<?php 
		$form->endForm();
		$form->render();
	}
	
	function afc_page() {
		Sys::importLib("afc", true);
		
		function testAfc($postData) {
			print_r($postData);
		}
		afc::registerFunction("testAfc");
		?>
		<input type="button" onclick="pd.afc.call('testAfc', 'param1=1&param2=2', function(){})" value="Call" />
		<?php
	}
	
	 
}
?>